create_bias_measures <- function(make_bias_dat)
{  
  europe <- c("Northern Europe", "Southern Europe", "Western Europe", 
              "Eastern Europe")
  EU95 <- c("Belgium", "France", "Netherlands", "Italy", "Luxembourg", 
            "Germany", "Denmark", "Ireland", "United Kingdom", "Greece", "Portugal",
            "Spain", "Austria", "Finland", "Sweden")
  EU_CEE <- c("Cyprus", "Czech Republic", "Estonia", "Hungary", "Latvia",
              "Lithuania", "Malta", "Poland", "Slovakia", "Slovenia", 
              "Bulgaria", "Romania")
  subsaharan <- c("Eastern Africa", "Western Africa", "Southern Africa",
                  "Middle Africa")
  oceania <- c("Micronesia", "Polynesia", "Melanesia", "Australia and New Zealand")
  namerica <- c("Northern America", "Caribbean")
  oecd <- c("Austria", "Belgium", "Canada", 
            "Denmark",  "Finland", "France", "Germany", "Greece", 
            "Iceland", "Ireland", "Italy", "Japan", "Luxembourg",
            "Mexico", "Netherlands", "New Zealand", "Norway", "Portugal",
            "Spain", "Sweden", "Switzerland",
            "United Kingdom", "United States")
  north <- c("Austria", "Australia", "Belgium", "Bulgaria", "Canada", "Cyprus", 
             "Denmark", "Finland", "France", "Germany", "Greece", "Hungary", "Iceland", 
             "Ireland", "Italy", "Liechtenstein", "Malta",
             "Japan", "Luxembourg", "Netherlands", "New Zealand", "Norway",
             "Poland", "Portugal", "Romania", "Russian Federation", "Spain", "Sweden", 
             "Switzerland", "United Kingdom", "United States", "Turkey", "Albania", 
             "Andorra", "Estonia", "Latvia", "Lithuania", "Armenia", 
             "Moldova, Republic of", "Croatia", "Slovenia", 
             "Bosnia and Herzegovina", "Czech Republic", "Slovakia", 
             "Macedonia, the former Yugoslav Republic of", "Serbia", "Montenegro")
  #south <- setdiff(unique(bias_dat$origin_name), north)
  bias_dat <- make_bias_dat
  bias_dat[, origin := substr(bias_dat$dyad, 1, 3)]
  bias_dat[, dest := substr(bias_dat$dyad, 5, 7)]
  bias_dat[, origin_name := countrycode(origin, "iso3c", "country.name")]
  bias_dat[, dest_name := countrycode(dest, "iso3c", "country.name")]
  bias_dat[, region_o := countrycode(origin, "iso3c", "region")]
  bias_dat[, region_d := countrycode(dest, "iso3c", "region")]
  bias_dat$region_map <- bias_dat$region_d
  bias_dat$north_south <- bias_dat$region_o
  bias_dat$original_origins <- bias_dat$region_o
  bias_dat$north_south_o[bias_dat$origin_name %in% north] <- "Global North"
  bias_dat$north_south_o[bias_dat$origin_name %in% 
                           setdiff(unique(bias_dat$origin_name), north)] <- "Global South"
  bias_dat$north_south_d[bias_dat$dest_name %in% north] <- "Global North"
  bias_dat$north_south_d[bias_dat$dest_name %in% 
                           setdiff(unique(bias_dat$dest_name), north)] <- "Global South"
  bias_dat$region_o[bias_dat$origin_name %in% oecd] <- "OECD"
  bias_dat$region_o[bias_dat$region_o %in% subsaharan] <- "Sub-Saharan Africa"
  bias_dat$region_o[bias_dat$region_o %in% oceania] <- "Oceania"
  bias_dat$region_o[bias_dat$region_o %in% namerica] <- "North America"
  bias_dat$region_o[bias_dat$region_o %in% europe] <- "Europe"
  bias_dat$region_d[bias_dat$region_d %in% europe] <- "Europe"
  bias_dat$region_d[bias_dat$region_d %in% subsaharan] <- "Sub-Saharan Africa"
  bias_dat$region_d[bias_dat$region_d %in% oceania] <- "Oceania"
  bias_dat$region_d[bias_dat$region_d %in% namerica] <- "North America"
  bias_dat$region_d[bias_dat$dest_name %in% oecd] <- "OECD"
  bias_dat$region_map[bias_dat$region_map %in% europe] <- "Europe"
  bias_dat$region_map[bias_dat$region_map %in% subsaharan] <- "Sub-Saharan Africa"
  bias_dat$region_map[bias_dat$region_map %in% oceania] <- "Oceania"
  bias_dat$region_map[bias_dat$region_map %in% namerica] <- "North America"
  bias_dat[, region_bias := mean(bias), by = .(dest_name, region_o, year)]
  bias_dat[, dwloss := ifelse(bias < 0, -exp(abs(bias)), exp(bias))]
  bias_dat[, plot_years := paste(as.numeric(year) + 1, "-", 
                                 as.numeric(year) + 5, sep = "")]
  bias_dat[, plot_regions := paste0("From: ", region_o)]
}